package com.wx.chapter13.homework;

/**
 * @Author : 佩萁
 * Description :
 * @Create : 2023/7/26 - 17:20
 */
public class HomeWork04 {
    public static void main(String[] args) {
        String str = "abcs  aASA";
        countStr(str);
    }

    public static void countStr(String str) {
        if (str == null) {
            System.out.println("字符串不能为空");
            return;
        }
        int numCount = 0;
        int lowerCount = 0;
        int upperCount = 0;
        int otherCount = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                numCount += 1;
            } else if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
                lowerCount += 1;
            } else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
                upperCount += 1;
            } else {
                otherCount += 1;
            }
        }
        System.out.println("数字有 " + numCount+ "个");
        System.out.println("小写字母有 " + lowerCount+ "个");
        System.out.println("大写字母有 " + upperCount+ "个");
        System.out.println("其他字符有 " + otherCount+ "个");
    }
}
